class Job < ActiveRecord::Base

   def self.process_file
    @joblists = Document.find(:all, :conditions => {:status => '0'}, :order => "id ASC LIMIT 0,1")
    @joblists.each do |x|
      docid = x.id
      docfilename = x.docfile_file_name

      tempfile = docfilename.split('.')
      arg0 = "#{docid} #{docfilename}"
      tempname = tempfile[0]
      arg1 = "#{docid} #{tempname}.pdf"

      `echo Argument 0: #{arg0} Argument 1: #{arg1} >> hello2.log`
      torun = "sh #{RAILS_ROOT}/vendor/script/converter.sh #{arg0}"
      @output = `#{torun}`
      puts @output

      getwidth = "sh  #{RAILS_ROOT}/vendor/script/getwidth.sh #{arg1}"
      getheight = "sh #{RAILS_ROOT}/vendor/script/getheight.sh #{arg1}"
      getpages = "sh #{RAILS_ROOT}/vendor/script/getpages.sh #{arg1}"



      @output1 = `#{getwidth}`
      puts "Width of the PDF is #{@output1}"
      x.page_width = @output1
      @output2 = `#{getheight}`
      puts "Height of the PDF is #{@output2}"
      x.page_height = @output2
      @output3 = `#{getpages}`
      puts "Total number of pages in the PDF is #{@output3}"
      x.num_pages = @output3
      x.status = '1'
      x.save

    end
  end
end
  
